<template>
  <div>
    <el-form ref="dataForm" v-model="query" class="form" :rules="rules">
      <div class="flex">
        <div class="flex">
          <div class="flex-inner">
            <el-form-item prop="ck_007_sys_setting_time1">
              <el-checkbox v-model="query.ck_007_sys_setting_time1">开启门店资金每日自动结算</el-checkbox>
            </el-form-item>
            <el-form-item prop="ck_007_sys_setting_time2">
              <el-checkbox v-model="query.ck_007_sys_setting_time2">开启门店库存每日自动结转</el-checkbox>
            </el-form-item>
          </div>
          <div class="box" />
        </div>
        <el-form-item prop="hour">
          <span style="color: #ccc;">—</span> 每日  <el-input-number v-model="query.hour" controls-position="right" :min="0" :max="23" :precision="0" /> 时,自动日结
        </el-form-item>
      </div>
      <el-form-item prop="ck_007_sys_setting_2_13">
        <el-checkbox v-model="query.ck_007_sys_setting_2_13">红包提现自动审核</el-checkbox>
      </el-form-item>
      <el-divider />
      <h4>重量转换配置</h4>
      <el-form-item prop="ck_007_sys_setting_2_18">
        <el-checkbox v-model="query.ck_007_sys_setting_2_18">月结对账单对账明细表</el-checkbox>
      </el-form-item>
      <el-form-item prop="ck_007_sys_setting_2_19">
        <el-checkbox v-model="query.ck_007_sys_setting_2_19">销售金额统计</el-checkbox>
      </el-form-item>
      <el-form-item prop="ck_007_sys_setting_2_20">
        <el-checkbox v-model="query.ck_007_sys_setting_2_20">客户用气量统计</el-checkbox>
      </el-form-item>
      <el-form-item prop="ck_007_sys_setting_sp4_26">
        <el-checkbox v-model="query.ck_007_sys_setting_sp4_26">配送员业绩统计</el-checkbox>
      </el-form-item>
      <el-divider />
      <el-form-item prop="ck_007_sys_setting_2_30">
        <el-checkbox v-model="query.ck_007_sys_setting_2_30">客户预付卡充值审核</el-checkbox>
      </el-form-item>
    </el-form>
  </div>
</template>

<script>
  import { mapGetters } from 'vuex'
  import moment from 'dayjs'

  export default {
    name: 'SettlementTab',
    data() {
      return {
        query: {
          hour: '',
          ck_007_sys_setting_time1: false,
          ck_007_sys_setting_time2: false,
          ck_007_sys_setting_2_13: false,
          ck_007_sys_setting_2_18: false,
          ck_007_sys_setting_2_19: false,
          ck_007_sys_setting_2_20: false,
          ck_007_sys_setting_sp4_26: false,
          ck_007_sys_setting_2_30: false
        },
        rules: {

        }
      }
    },
    computed: {
      ...mapGetters([
        'corpSettingData', 'userInfo'
      ])
    },
    created() {
      this.init()
    },
    methods: {
      init() {
        if (this.corpSettingData) {
          if (this.corpSettingData.time1) {
            this.query.ck_007_sys_setting_time1 = true
          }
          if (this.corpSettingData.time2) {
            this.query.ck_007_sys_setting_time2 = true
          }
          const min_date = new Date('1991-01-01').getTime()
          let hour
          if (this.corpSettingData.time1 && moment(this.corpSettingData.time1).valueOf() >= min_date) {
            const time1 = (this.corpSettingData.time1)
            const str1 = moment(time1).format('HH:mm:ss')
            if (str1 === '23:59:59') {
              hour = 0
            } else {
              hour = new Date(time1).getHours()
            }
            this.query.hour = hour
          }
          if (this.corpSettingData.time2 && moment(this.corpSettingData.time2).valueOf() >= min_date) {
            const time2 = (this.corpSettingData.time2)
            const str2 = moment(time2).format('HH:mm')
            if (str2 === '23:59') {
              hour = 0
            } else {
              hour = new Date(time2).getHours()
            }
            this.query.hour = hour
          }
          this.query.ck_007_sys_setting_2_13 = !!(this.corpSettingData.sp2 >> 13 & 0x01)
          this.query.ck_007_sys_setting_2_18 = !!(this.corpSettingData.sp2 >> 18 & 0x01)
          this.query.ck_007_sys_setting_2_19 = !!(this.corpSettingData.sp2 >> 19 & 0x01)
          this.query.ck_007_sys_setting_2_20 = !!(this.corpSettingData.sp2 >> 20 & 0x01)
          this.query.ck_007_sys_setting_sp4_26 = !!(this.corpSettingData.sp4 >> 26 & 0x01)
          this.query.ck_007_sys_setting_2_30 = !!(this.corpSettingData.sp2 >> 30 & 0x01)
        }
      }
    }
  }
</script>

<style lang="scss" scoped>
.form {
  .el-form-item {
    margin-bottom: 0;
  }
}
.flex {
  display: flex;
  align-items: center;
  .flex-inner {
    display: flex;
    flex-direction: column;
    align-items: center;
  }
  .box {
    width: 30px;
    height: 30px;
    margin-left: 5px;
    border-top: 1px solid #ccc;
    border-right: 1px solid #ccc;
    border-bottom: 1px solid #ccc;
  }
}
</style>
